The way I solved this problem was to use two SwiftUI files. the first file was like this:
@FetchRequest(sortDescriptors: []) var stats: FetchedResults<PlayerStats>
var body: some View {
Stats2View(stats: Array(stats))
}
}
The second file has most of your original code but adding one line.
// Add this
@State var stats:Array<PlayerStats>
@State private var sortOrder = [KeyPathComparator(\PlayerStats.name)]
var body: some View {
if #available(iOS 16.0, *) {
Table(stats, sortOrder: $sortOrder) {
TableColumn("Player", value: \.name!)
TableColumn("W-L", value: \.wins) {stats in Text("\(stats.wins)" + " - " + "\(stats.losses)")}
TableColumn("Points", value: \.points) {stats in Text("\(stats.points)")}
TableColumn("Innings", value: \.innings) {stats in Text("\(stats.innings)")}
TableColumn("LR", value: \.longRun) {stats in Text("\(stats.longRun)")}
TableColumn("Avg", value: \.lastAvg) {stats in Text("\((stats.lastAvg), specifier: "%.3f")")}
}
.onChange(of: sortOrder) { newOrder in
stats.sort(using: newOrder)}
}
else {...} \\old hacky lazyVGrid based table
}
}
Post
Replies
Boosts
Views
Activity
Remove the HSplitView. This should give you three sections.